class Position < ActiveRecord::Base
	belongs_to :technology, :foreign_key => "technology_id" 
	belongs_to :team, :foreign_key => "team_id" 
	belongs_to :ovposition, :foreign_key => "ovposition_id" 
	belongs_to :wave, :foreign_key => "wave_id" 
	def complete_position_name
		"#{id} - #{name} | #{technology.name} | #{team.name} | #{ovposition.name}"
	end
        def in_use
          a = Assignation.find_by_sql(["SELECT * from assignations a where position_id = ? and active = 1",id])
          if a[0]
            "In Use"
          else
            "Free"
          end
          #memberT = Member.find_by_sql(["SELECT m.* FROM members m WHERE m.id = ?",member.id])
          #memberThis.lastname
        end
	
	def position_label
		"#{id} - #{name}"
	end

	def validate
	    	    errors.add("Name:","You must enter the Position Title") if not name or name == ""
	       	    errors.add("Head Count Approval Date:","You must enter a headcount approval date") if not hc_approval_date
		    errors.add("Priority Date:","You must enter a priority date") if not priority_date
    	    	    errors.add("Hiring Type:","You must enter the Hiring Type") if not hiring_type
    	    	    errors.add("Seniority:","You must enter the Seniority for the position") if not seniority
    	    	    errors.add("Technology:","You must enter the Technology for the position") if not technology
    	    	    errors.add("Team:","You must enter the Team for the position") if not team
    	    	    errors.add("OneWorld Position:","You must enter the OneWorld Position Title") if not ovposition
		    errors.add("Wave:","You must enter the Wave for the position") if not wave


        end
end
